package com.baichang.taoshunda.dao.impl;

import com.baichang.framework.excelption.DBException;
import com.baichang.framework.model.Page;
import org.apache.commons.lang.StringUtils;
import org.springframework.stereotype.Repository;

import com.baichang.framework.dao.impl.BaseDaoImpl;
import com.baichang.taoshunda.dao.ParamsTypeDao;
import com.baichang.taoshunda.entity.ParamsType;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

@Repository
public class ParamsTypeDaoImpl extends BaseDaoImpl<ParamsType> implements ParamsTypeDao {

    /**
     * 参数类型的列表查询
     */

    @Override
    public Page<Map<String, Object>> paramsType(int nowPage, int pageSize, int typeId, String paramsName) throws DBException {
        List<Object> params = new ArrayList<Object>();
        String sql;
        if (typeId == 0) {
            sql = "select * from t_params_type a where a.state=1";
            if (StringUtils.isNotBlank(paramsName)) {
                sql += " and a.name like ?";
                params.add("%" + paramsName + "%");
            }
        } else {
            sql = "select * from t_params a where a.type_id=? and a.state=1";
            params.add(typeId);
            if (StringUtils.isNotBlank(paramsName)) {
                sql += " and a.name like ?";
                params.add("%" + paramsName + "%");
            }
        }
        return pageForMapList(sql, nowPage, pageSize, params.toArray());
    }

    /**
     * 修改参数
     *
     * @param map 内容
     * @param id  编号
     * @return
     */
    public int update(Map<String, Object> map, int id) {
        return update(" id=? ", map, id);
    }


}